package com.atguigu.base.v2;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Ticket {
    private int number = 50;
    private final Lock L = new ReentrantLock();


    public synchronized void sale(){
        L.lock();
        try{
            if(number>0){
                System.out.println(Thread.currentThread().getName()+"\t"+"卖了第"+ (number--));
            }
        }finally {
            L.unlock();
        }
    }
}
